import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class ProviderCounter with ChangeNotifier, DiagnosticableTreeMixin {
  int _count = 0;
  int get count => _count;

  void increment() {
    _count++;
    print('++++');
    notifyListeners(); // 通知所有监听者
  }

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    // TODO: implement debugFillProperties
    super.debugFillProperties(properties);
    properties.add(IntProperty('count', count));
  }
}

class ProviderName extends ChangeNotifier {
  int _count = 1000;
  String _name = "仙道";

  int get count => _count;
  String get name => _name;

  void increment() {
    _count++;
    notifyListeners();
  }

  void changeName() {
    _name = "仙道最厉害";
    notifyListeners();
  }

  void updateName(String name) {
    _name = name;
    notifyListeners();
  }
}

/// 模拟异步加载数据
class DataProvider extends ChangeNotifier {
  String _data = '';
  bool _isLoading = true;

  String get data => _data;
  bool get isLoading => _isLoading;

  DataProvider() {
    fetchData();
  }

  Future<void> fetchData() async {
    await Future.delayed(Duration(seconds: 2));
    _data = 'Fetched data';
    _isLoading = false;
    notifyListeners();
  }
}
